﻿var SubscribecnArray;//存储用户预约记录的数组

//根据邮箱，名字查询所有受邀记录，由state判断选择显示
function selectSubscribeSonByEmailAndName_Invite(email,name,state) {
       //alert(email+""+name+""+state);
    //更改为可查询全部记录的链接
    var selectSubscribeSonByEmailAndName_Invite_URL = URL_1+"selectSubscribeSonByEmailAndName"; 
	//alert(selectSubscribeSonByEmailAndName_Invite_URL );
    $.ajax({
        url: selectSubscribeSonByEmailAndName_Invite_URL,
        type: 'GET',
        dataType: 'json',
        cache: false,
        data:{
          subscribe_user_email:email,
          subscribe_user_name:name
        },
        beforeSend: LoadFunction, //加载执行方法
        error: erryFunction, //错误执行方法
        success: succFunction //成功执行方法
    })

    function LoadFunction() {
        //$(".header1").html('加载中...');
    }

    function erryFunction() {
        window.native.toast("获取-邀约记录-超时");
    }

    function succFunction(JsonString) {

        var title_color;
	var coo;
	
        json = eval(JsonString);
	//alert(json);
//alert(JsonString);
        if (json.code > 0) {  
            var dataJson = json.extend.selectByEmailAndName;
            SubscribecnArray = new Array(dataJson.length);
            var htmlString = "";
            for (var i = 0; i < dataJson.length; i++) {
			  	SubscribecnArray[i]=dataJson[i];
			  	//解析JSON
			  	var subscribeUserStatus = dataJson[i]["subscribeUserStatus"];
			  	if(subscribeUserStatus == state){
                    var subscribeBeginTime = fmtDate(dataJson[i]["subscribeBeginTime"]);
			  		var id = dataJson[i]["id"];
				  	var subscribeEndTime = fmtDate(dataJson[i]["subscribeEndTime"]);
				  	var mainName = dataJson[i]["mainName"];
				  	var subscribeUserStatusName = dataJson[i]["subscribeUserStatusName"];
 var zhuangt =dataJson[i]["subscribeStatusName"];
//var zhuangt =dataJson[i]["StatusName"];
if(zhuangt=="已结束"){
coo='style="color:black;font-size:12px"'
}else{
coo='style="color:#42A5F5;font-size:12px"'
}
                     //    alert(subscribeBeginTime);
                      //    alert(subscribeEndTime);
                      //     alert(mainName);
                   
                      //       alert(fmtDateym(subscribeBeginTime,subscribeEndTime));
                      
                    var end = new Date(dataJson[i]["subscribeEndTime"]);
                var weekStr = "星期" + "日一二三四五六".charAt(end.getDay());
				  
				  
				  
				  	 var endTime = fmtDate(dataJson[i]["subscribeEndTime"]).substring(11,16);
                var  startTime = fmtDate(dataJson[i]["subscribeBeginTime"]).substring(11,16);
                var month = fmtDate(dataJson[i]["subscribeBeginTime"]).substring(5,7);
                var day = fmtDate(dataJson[i]["subscribeBeginTime"]).substring(8,10);
                
	                htmlString +="<li "+coo+" class=\"mui-table-view-cell\" style=\"color:#42A5F5;font-size:12px\"\" onclick=\"subscribeOnclick(\'"+id+"\')\"><div style=\"width:100%\;\"><div style=\"width:30%;text-align:center;float:left;\">"+mainName+
	                "</div><div style=\"width:40%;text-align:center;float:left;\">"
	                +month+"-"+day+" "+weekStr+" "+ startTime + "~" + endTime +
	                "</div><div style=\"width:30%;text-align:center;float:left;padding-left:30px;\">"+zhuangt+"</div></div></li>"
			  	}else{
			  		/*Do Nothing*/
			  	}	
            }
            if(htmlString==""){  
            	htmlString = " <li class=\"mui-table-view-cell\" style=\"text-align:center;\"> 暂 无 记 录</li>";	
            }
         // alert(htmlString);
            //渲染数据
            document.getElementById('liebiao_a').innerHTML=htmlString;
            
        } else {
            window.native.toast(json.msg);
        }
    }
};

/*
function selectBySubscribeSonId(Invite_id){

    根据这个id
    http://10.44.12.173:8080/Subscribe/selectBySubscribeSonId?id=217a6478-bac1-42df-8c21-8d33337
    查询出来渲染数据

 //更改为可查询全部记录的链接
    var selectBySubscribeSonId_Invite_URL = URL_1+"selectBySubscribeSonId"; 

    $.ajax({
        url: selectBySubscribeSonId_Invite_URL,
        type: 'GET',
        dataType: 'json',
        cache: false,
        data:{
          id:Invite_id
        },
        beforeSend: LoadFunction, //加载执行方法
        error: erryFunction, //错误执行方法
        success: succFunction //成功执行方法
    })

    function LoadFunction() {
        $(".header1").html('加载中...');
    }

    function erryFunction() {
        window.native.toast("获取-邀约信息查询-超时");
    }

    function succFunction(JsonString) {
        json = eval(JsonString);
        if (json.code > 0) {  
            var objArray= json.extend.selectByPrimaryKeyWithDevice;
            for(var i = 0 ; i <objArray.length;i++){
                //alert(objArray[i].name);
            }
            
        } else {
            window.native.toast(json.msg);
        }
    }
};
*/



function subscribeOnclick(Invite_id){
 
   var flage="MyInvitePage";//1代表 从 我的预约界面 跳转
   openOrderDetailedWin("InviteDetailed",Invite_id,flage);

}



function openOrderDetailedWin(name,Invite_id,flage) {
       window.location.href = "InviteDetailed.html?OrderId="+Invite_id+"&Pageflage="+flage+"";
}
function fmtDateym(stime,etime) {
    var startTime = new Date(stime);
    var endTime = new Date(etime);
    var weekStr = "星期" + "日一二三四五六".charAt(startTime.getDay());
//  var y = date.getFullYear();
    var m = startTime.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = startTime.getDate();
    d = d < 10 ? ('0' + d) : d;
    var startHour = startTime.getHours();
    startHour = startHour < 10 ? ('0' + startHour) : startHour;
    var startminute = startTime.getMinutes();
    startminute = startminute < 10 ? ('0' + startminute) : startminute;
    
    var endHour = endTime.getHours();
    endHour = endHour < 10 ? ('0' + endHour) : endHour;
    var endminute = endTime.getMinutes();
    endminute = endminute < 10 ? ('0' + endminute) : endminute;
    
    var result = m + '-' + d + ' ' +weekStr +" "+ startHour + ':' + startminute + '~'
    + endHour +":"+ endminute;
    return result;
};


function fmtDate(obj) {
    var date = new Date(obj);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
}


